package com.teach.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.dto.ProductSearch;
import com.teach.entity.Product;
import com.teach.mapper.ProductMapper;
import com.teach.service.shop.ShopAdminServlet;

@Service
public class ShopAdminServiceImpl implements ShopAdminServlet{
	
	@Autowired
	ProductMapper mapper;
	
	@Override
	public PageInfo<Product> page(ProductSearch search) {
		PageInfo<Product> page = PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->{
			mapper.select(search);
		});
		return page;
	}

	@CacheEvict(value = "product", key = "#product.productOut")
	@Override
	public void modify(Product product) {
		mapper.updateByPrimaryKeySelective(product);
	}
	
	@CacheEvict(value = "product", key = "#product.productId")
	@Override
	public void doDelete(Product product) {
		mapper.deleteByPrimaryKey(product.getProductId());
	}
	
	@CacheEvict(value = "product", key = "#product.productClassId")
	@Override
	public void doProductClass(Product product) {
		mapper.updateByPrimaryKeySelective(product);
	}
	
	@CacheEvict(value = "product", key = "#productId")
	@Override
	public Product doModifyProduct(Long productId) {
		return mapper.selectByPrimaryKey(productId);
	}
}
